<?php
$_GET["get"]==null ? header("Location:index.php?get=1") : '';
switch ($_GET["get"]){
    case "1":
        if (file_exists("install.lock")){
            exit("程序已安装，如未安装，请删除install/install.lock安装锁在访问网站");
        }
        echo('<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <title>云风轻程序安装向导</title>

    <!-- Favicon -->
    <link rel="shortcut icon" type="../image/x-icon" href="assets/img/favicon.png">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../assets/install/css/bootstrap.min.css">

    <!-- Fontawesome CSS -->
    <link rel="stylesheet" href="../assets/install/css/font-awesome.min.css">

    <!-- Main CSS -->
    <link rel="stylesheet" href="../assets/install/css/style.css">

    <!--[if lt IE 9]>
    <script src="assets/js/html5shiv.min.js"></script>
    <script src="assets/js/respond.min.js"></script>
    <![endif]-->
</head>
<body><div class="main-wrapper login-body">
    <div class="login-wrapper">
        <div class="container">
            <div class="loginbox">
                <div class="login-left">
                    <a href="https://www.pureyun.com"><img class="img-fluid" src="https://author.airycloud.cn/Static/logo.png" alt="Logo"></a>
                </div>
		<!-- Main Wrapper -->
                        <div class="login-right">
							<div class="login-right-wrap">
								<h1 style="color:red">安装向导</h1>
								<p class="account-subtitle">请仔细阅读以下安装协议</p>
								<p>1.本项目旨在记录平台中的黑名单用户账号信息，请勿恶意记录他人信息，如造成不良后果全由使用者承担<p><br>
                                <p>3.程序已经在gitee开源，请勿进行二次向外销售<br></p>
								<!-- Form -->
								<a href="index.php?get=2" class="btn btn-primary btn-block" type="submit">同意安装协议，下一步</a>
							</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		<!-- /Main Wrapper -->
		
		<!-- jQuery -->
    </body>
</html>');
        break;
    case "2":
        if (file_exists("install.lock")){
            exit("程序已安装，如未安装，请删除install/install.lock安装锁在访问网站");
        }
        if (isset($_POST["submit"])){
            if (function_exists('php_pdo_mysql')){
                die(json_encode(["status"=>3,"msg"=>"pdo扩展未打开，不支持安装此程序"]));
            }
            if (PHP_VERSION < '7.0'){
                die(json_encode(["status"=>3,"msg"=>"php版本小于7.0，不支持安装此程序"]));
            }
            $host=$_POST["host"];
            $port=$_POST["port"];
            $name=$_POST["name"];
            $user=$_POST["user"];
            $pass=$_POST["pass"];
            $token=$_POST["token"];
            try {
@$pdo=new PDO("mysql:host={$host};dbname={$name};port={$port};charset=utf8",$user,$pass);
$sql=file_get_contents('pz.sql');
$config=fopen('../system/config.php','w');
$sqldata='<?php
$con=array(
    "dbhost"=>"'.$host.'",
    "dbport"=>"'.$port.'",
    "dbname"=>"'.$name.'",
    "dbuser"=>"'.$user.'",
    "dbpass"=>"'.$pass.'",
    "token"=>"'.$token.'",
);
?>';
fwrite($config,$sqldata);
$sql_arr=explode(";",$sql);
foreach ($sql_arr as $key=>$value){
@$pdo->exec($value);
}
$status='1';
$msg="恭喜你安装程序成功";
fopen("install.lock","w");
            }catch (PDOException $e){
                $status='0';
                $msg="数据库链接出错，请仔细核实";
            }
            die(json_encode(["status"=>$status,"msg"=>$msg]));
        }else{
        echo('<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <title>云风轻程序安装向导</title>

    <!-- Favicon -->
    <link rel="shortcut icon" type="../image/x-icon" href="assets/img/favicon.png">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../assets/install/css/bootstrap.min.css">

    <!-- Fontawesome CSS -->
    <link rel="stylesheet" href="../assets/install/css/font-awesome.min.css">

    <!-- Main CSS -->
    <link rel="stylesheet" href="../assets/install/css/style.css">

    <!--[if lt IE 9]>
    <script src="assets/js/html5shiv.min.js"></script>
    <script src="assets/js/respond.min.js"></script>
    <![endif]-->
</head>
<body><div class="main-wrapper login-body">
    <div class="login-wrapper">
        <div class="container">
            <div class="loginbox">
                <div class="login-left">
                    <a href="https://author.airycloud.cn">云风轻程序安装导航</a>
                </div>
                        <div class="login-right">
							<div class="login-right-wrap">
									<h1 style="color:red">安装向导_2</h1>
								<p class="account-subtitle">请认真填写数据库信息</p>
								
								<!-- Form -->
									<div class="form-group">
										<input class="form-control" id="host" type="text" placeholder="数据库地址">
									</div>
									<div class="form-group">
										<input class="form-control" id="port" type="text" value="3306" placeholder="数据库端口(默认3306)">
									</div>
									<div class="form-group">
										<input class="form-control" id="name" type="text"  placeholder="数据库名称">
									</div>
									<div class="form-group">
										<input class="form-control" id="user" type="text" placeholder="数据库用户名">
									</div>
									<div class="form-group">
										<input class="form-control" id="pass" type="text" placeholder="数据库密码">
									</div>
										<div class="form-group">
										<input class="form-control" id="token" type="text" value="(PHP、JAVA)项目开发联系QQ65288050" placeholder="云风轻授权中心token">
									</div>
									<div class="form-group">
										<button id="submit" class="btn btn-primary btn-block" type="submit">完成安装</button>
									</div>
							</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		<!-- /Main Wrapper -->
		<script src="../assets/install/js/jquery-3.2.1.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
<script src="../assets/layer.js"></script>
<script >
$(function (){
 $("#submit").click(function() {
     var index = layer.load(2, {
  shade: [0.1,"#fff"] //0.1透明度的白色背景
});
   var host=$("#host").val();
   var port=$("#port").val();
   var name=$("#name").val();
   var user=$("#user").val();
   var pass=$("#pass").val();
   var token=$("#token").val();
   if (!user || !pass ||!host || !name || !port || !token){
       layer.close(index);
       swal({
        title: "OK!",    
        text: "Nice to meet you!",
        type: "success",    
        confirmButtonText: "HaHa" 
    })
       swal ( "失败！" ,  "有参数输入为空!" ,  "error");
   }else{
   	$.ajax({
		url: "index.php?get=2",
		type: "POST",
		dataType: "json",
		data: {host:host,port:port,name:name,user:user,pass:pass,token:token,submit:"1"},
	})
	.done(function(data) {
	    if (data.status==3){
	        layer.msg(data.msg, {icon: 2});
	        layer.close(index);
	    }
		if (data.status==0){
swal ( "失败！" ,  data.msg ,  "error");
 layer.close(index);
}
				if (data.status==1){
             
                    swal ( "恭喜你，安装成功！！！" ,  data.msg ,  "succcess");
 layer.close(index);
 window.location.href="./index.php?get=3";
}
	})
	.fail(function(data) {
		alert("data.msg");
	});
   	}
 });
});
</script>
		<!-- jQuery -->
</body>
</html>');
        }
        break;
    case "3":
        echo('<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <title>云风轻程序安装向导——安装成功</title>

    <!-- Favicon -->
    <link rel="shortcut icon" type="../image/x-icon" href="assets/img/favicon.png">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../assets/install/css/bootstrap.min.css">

    <!-- Fontawesome CSS -->
    <link rel="stylesheet" href="../assets/install/css/font-awesome.min.css">

    <!-- Main CSS -->
    <link rel="stylesheet" href="../assets/install/css/style.css">

    <!--[if lt IE 9]>
    <script src="assets/js/html5shiv.min.js"></script>
    <script src="assets/js/respond.min.js"></script>
    <![endif]-->
</head>
<body><div class="main-wrapper login-body">
    <div class="login-wrapper">
        <div class="container">
            <div class="loginbox">
                <div class="login-left">
                 云风轻程序安装导航
                </div>
		<!-- Main Wrapper -->
                        <div class="login-right">
							<div class="login-right-wrap">
								<h1 style="color:red">恭喜你，安装程序成功</h1>
								<p class="account-subtitle">快进入自己的网站看看吧</p>
                                <p class="account-subtitle">默认后台账号密码:admin||123456</p>
								<a href="../" class="btn btn-primary btn-block" type="submit">进入网站首页</a>
								<a href="../admin" class="btn btn-success btn-block" type="submit">进入后台界面</a>
							</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		<!-- /Main Wrapper -->
		
		<!-- jQuery -->
    </body>
</html>');
        break;

}
?>

